package edu.kit.aifb.ldstream.stat.util;

import java.util.LinkedList;
import java.util.List;

public class OctaveCheckerFactory implements IDistributionCheckerFactory{

	
	private List<IDistributionChecker> instances;
	private IDistributionChecker lastInstance;
	
	public OctaveCheckerFactory(){
		this.instances = new LinkedList<IDistributionChecker>();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public synchronized IDistributionChecker getNewDistributionChecker() {
		lastInstance = new OctaveFrontend();
		this.instances.add(lastInstance);
		return lastInstance;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public synchronized IDistributionChecker getLastInstance(){
		if(lastInstance == null){
			return getNewDistributionChecker();
		}
		return lastInstance;
	}

	/**
	 * {@inheritDoc}
	 */
	public void shutdown(){
		for(IDistributionChecker instance : this.instances){
			instance.shutdown();
		}
	}
	
}
